/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

package com.facebook.imagepipeline.postprocessors;

import com.facebook.cache.common.CacheKey;
import com.facebook.cache.common.SimpleCacheKey;
import com.facebook.imagepipeline.nativecode.NativeRoundingFilter;
import com.facebook.imagepipeline.request.BasePostprocessor;
import ohos.media.image.PixelMap;

import javax.annotation.Nullable;

public class RoundedCornersPostprocessor extends BasePostprocessor {

    private @Nullable
    CacheKey mCacheKey;

    @Override
    public void process(PixelMap bitmap) {
        int radius = Math.min(bitmap.getImageInfo().size.height, bitmap.getImageInfo().size.width);
        NativeRoundingFilter.addRoundedCorners(bitmap, radius / 2, radius / 3, radius / 4, radius / 5);
    }

    @Nullable
    @Override
    public CacheKey getPostprocessorCacheKey() {
        if (mCacheKey == null) {
            mCacheKey = new SimpleCacheKey("RoundedCornersPostprocessor");
        }
        return mCacheKey;
    }
}
